package com.hp.provider.web;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hp.provider.service.UserService;
import com.hp.common.common.Result;
import com.hp.provider.po.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dongxing
 * @since 2019-05-19
 */
@RestController
@RequestMapping("/mapper/config/user")
@AllArgsConstructor(onConstructor_={@Autowired})
@Api(tags = "用户的前端控制器")
public class UserController {

    private final UserService userService;

    @GetMapping("/{id}")
    @ApiOperation(value = "根据用户的id查询用户的信息")
    public Result findUserById(@PathVariable("id") String id) {
        User byId = userService.getById(id);
        return Result.createBySuccess(byId);
    }

    @PostMapping("/findUsers")
    @ApiOperation(value = "分页查询用户的信息")
    public Result findUserById(Integer pageNum,Integer pageSize) {
        BaseMapper<User> baseMapper = userService.getBaseMapper();
        Page<User> page = new Page<>(pageNum, pageSize);
        IPage<User> userIPage = baseMapper.selectPage(page, new QueryWrapper<User>().lambda().orderByDesc(User::getId));
        return Result.createBySuccess(userIPage);
    }

}
